﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using DoAnASP;

public partial class _Default : System.Web.UI.Page
{
    DTO_NhanVien nv = new DTO_NhanVien(); // load lên đê cap nhat
    DTO_NhanVien nv1 = new DTO_NhanVien();// dùng để cập nhật
    DataTable dt = new DataTable();
   
    protected void Page_Load(object sender, EventArgs e)
    {
        lbQuyenTruyCap.Visible = false;
        ddlquyen.Visible = false;

        if (!IsPostBack)
        {
            CapNhapTT(nv);
        }

        
    }
    
    // khi dang nhâp thành cong và muôn cập nhật thông tin cá nhân
   public void CapNhapTT (DTO_NhanVien nv )
    {
      
        BUS_NhanVien nv1 = new BUS_NhanVien();
        
        nv.Username = Session["ThanhVien"].ToString();
        
        dt = nv1.LoadCaNhan(nv);
        if (dt.Rows.Count > 0)
        {
            txtTenDN.Text = dt.Rows[0]["TenDangNhap"].ToString();
            txtMatKhau1.Text = dt.Rows[0]["MatKhau"].ToString();
            txtMatKhau2.Text = dt.Rows[0]["MatKhau"].ToString();

            txtHoTen.Text = dt.Rows[0]["HoTen"].ToString();

            //lbmau.Text = dt.Rows[0]["MatKhau"].ToString();

            txtSDT.Text = dt.Rows[0]["SoDT"].ToString();
            txtDiaChi.Text = dt.Rows[0]["DiaChi"].ToString();
            txtEmail.Text = dt.Rows[0]["Email"].ToString();
            Session["IDThanhVien"] = (int)dt.Rows[0]["IDNguoiDung"];
            //Session["I"] = (int)dt.Rows[0]["MaQuyen"];
           
        }

    }

   // Session["IDThanhVien"]


    protected void btnCapNhat_Click(object sender, EventArgs e)
    {
       
        nv1.Username = txtTenDN.Text;

        nv1.Password = txtMatKhau1.Text;
        txtMatKhau1_TextChanged(sender, e); // neu co thay đổi sẽ lay cái này
       
        txtMatKhau1_Load(sender, e);

        nv1.FullName = txtHoTen.Text;
        txtHoTen_TextChanged(sender, e);

        nv1.NumBerPhone = txtSDT.Text;
        txtSDT_TextChanged(sender, e);

        nv1.Address = txtDiaChi.Text;
        txtDiaChi_TextChanged(sender, e);

        nv1.Email = txtEmail.Text;
        txtEmail_TextChanged(sender, e);

        nv1.IDThanhVien = (int)Session["IDThanhVien"];
        nv1.IDQuyenTruyCap = (int)Session["MaQuyen"];

        BUS_NhanVien nv2 = new BUS_NhanVien();
        bool kt =  nv2.CapNhatThongTT(nv1);
        if (kt == true)
        {
            Session["MaTB"] = 5;
            Response.Redirect("ThongBao.aspx");
        }

    }
    protected void txtSDT_TextChanged(object sender, EventArgs e)
    {
        nv1.NumBerPhone = txtSDT.Text;
    }
    protected void txtDiaChi_TextChanged(object sender, EventArgs e)
    {
        nv1.Address = txtDiaChi.Text;
    }
    protected void txtEmail_TextChanged(object sender, EventArgs e)
    {
        nv1.Email = txtEmail.Text;
    }
    protected void txtMatKhau1_TextChanged(object sender, EventArgs e)
    {
        nv1.Password = txtMatKhau1.Text;
    }
    protected void txtHoTen_TextChanged(object sender, EventArgs e)
    {
        nv1.FullName = txtHoTen.Text;
    }
    protected void txtHoTen_Load(object sender, EventArgs e)
    {

    }
    protected void txtMatKhau1_Load(object sender, EventArgs e)
    {

    }
    protected void btnHuy_Click(object sender, EventArgs e)
    {
        Response.Redirect("trangChu.aspx");
    }
}